﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evan.Common
{
    public static class StrEncrypt
    {
        /// <summary>
        /// 文本加密
        /// </summary>
        /// <param name="content">需要加密的内容</param>
        /// <param name="secretKey">秘钥</param>
        /// <returns></returns>
        public static char[] TextEncrypt(string content, string secretKey)
        {
            char[] data = content.ToCharArray();
            char[] key = secretKey.ToCharArray();
            for (int i = 0; i < data.Length; i++)
            {
                data[i] ^= key[i % key.Length];
            }
            return data;
        }
        /// <summary>
        /// 文本解密
        /// </summary>
        /// <param name="data">加密的内容</param>
        /// <param name="secretKey">秘钥</param>
        /// <returns></returns>
        public static string TextDecrypt(char[] data, string secretKey)
        {
            char[] key = secretKey.ToCharArray();
            for (int i = 0; i < data.Length; i++)
            {
                data[i] ^= key[i % key.Length];
            }
            return new string(data);
        }
    }
}
